/** 
 * @author Huang RuiGuang
 * @date 2008/12/1
 *
 * Herm library
 * Copyright (c) 2008 by Huang RuiGuang(daemon.huang@gmail.com)
 *
 * Permission to use, copy, modify, distribute and sell this software.
 */

#ifndef HERM_FRAMEWORK_LOCAL_SESSION_H
#define HERM_FRAMEWORK_LOCAL_SESSION_H

#include "herm/base/network/interface.h"
#include "herm/base/network/common_handler.h"

namespace herm{
	class Buffer;
}

class LocalSession : public herm::ISession,
				     private CommonHandler
{
public:
	LocalSession(const herm::LPeerParam& peerParam);
	~LocalSession(void);

protected: // LocalSession::Read can be invoked by NonblockConnectTCPSession
	/**
	* @brief, read data from receiving queue.
	* @param buf, store fetched data.
	* @param len, indicate buf size and return data length.
	*        Note @len of inputing must is max value of protocol msg!
	*/
	virtual int Fetch(char* buf, int& len) const;
	/**
	* @brief, write data to sending queue.
	*/
	virtual int Push(const char* buf, int len);

    // herm::ISession virtual function
	virtual int GetIndex();
	virtual void RegisterHandler(herm::IMsgHandler* handler);
	virtual herm::IMsgHandler* GetHandler() const;
	virtual const herm::Address& GetLocalAddr() const { return m_nulAddr; }
	virtual const herm::Address& GetRemoteAddr() const { return m_nulAddr; }
    virtual bool IsSendBufferEmpty() const;
    virtual herm::IPeer* GetPeer() { return nullptr; }
    virtual const herm::IPeer* GetPeer() const { return nullptr; }
private:
	herm::Address m_nulAddr;
	herm::Buffer* m_buffer;
	char* m_tmpBuf;
	herm::uint32_t m_index;
	herm::LPeerParam m_peerParam;
	herm::IMsgHandler* m_msgHandler;
};

#endif
